<?php
namespace core;
/**
 * HTTP请求
 */

class Http
{
  static public $timeout=10000;
	static public $userAgent='CORE API Client (v 0.1)';

	static function post($url,$data){

		$options = array(
			'http'=>array(
			'method'=>"POST",
			'timeout' => self::$timeout,


			'header'  => array(
				"User-Agent: ".self::$userAgent,
				"Content-type: application/x-www-form-urlencoded",

				),
			'content' => http_build_query($data),
			)
		);

		$context = stream_context_create($options);
		$cnt=0;
		while($cnt < 3 && ($str=@file_get_contents($url, false, $context))===FALSE) $cnt++;

		return $str;


	}
	static function get($url){

		$options = array(
			'http'=>array(
			'method'=>"GET",
			'timeout' => self::$timeout,
			'header'  => array(
				"User-Agent: ".self::$userAgent,
				),

			)
		);

		$context = stream_context_create($options);
		$cnt=0;
		while($cnt < 3 && ($str=@file_get_contents($url, false, $context))===FALSE) $cnt++;

		return $str;


	}

}


?>
